home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
UUPC3
/
MAC_SPEC
/
UNIX_LIB
/
CHDIR.C
next >
Wrap
C/C++ Source or Header
|
1991-12-04
|
2KB
|
89 lines
#include "host.h"
#ifdef THINK_C
# include "unixlibproto.h"
#endif THINK_C
#include <string.h>
#ifdef TEST
# include <stdio.h>
#endif TEST
#ifndef NULL
#define NULL 0L
#endif
chdir( path )
char * path;
{
char npath[255];
CInfoPBRec cpb;
WDPBRec wdpb;
int vRef;
/* get default WD id */
(void)GetVol((StringPtr)npath, &vRef);
/* convert to Mac-style pathname */
cnvMac( path, npath );
#ifdef NOTDEF
cpb.dirInfo.ioVRefNum = 0;
cpb.dirInfo.ioNamePtr = (StringPtr)CtoPstr(npath);
cpb.dirInfo.ioFDirIndex = 0;
cpb.dirInfo.ioDrDirID = 0L;
#ifdef TEST
fprintf( stderr, "opendir: %s\n", buf );
#endif
if (PBGetCatInfo( &cpb, 0 ) != noErr ) {
#ifdef TEST
fprintf( stderr, "setdir: PBGetCatInfo %d\n", err );
#endif
return((int)NULL);
}
#ifdef THINK_C
memset((char *)(&wdpb), (int)NULL, (size_t)sizeof(wdpb));
#else THINK_C
repmem((char *)&wdpb, "", 1, sizeof(wdpb));
#endif THINK_C
wdpb.ioVRefNum = cpb.dirInfo.ioVRefNum;
wdpb.ioWDProcID = 'UUPC';
wdpb.ioWDDirID = cpb.dirInfo.ioDrDirID;
if (PBOpenWD(&wdpb, FALSE) != noErr) {
return((int)NULL);
}
if (SetVol((int)NULL, wdpb.ioVRefNum) != noErr) {
return((int)NULL);
}
#else
memset((char *)(&wdpb), (int)NULL, (size_t)sizeof(wdpb));
wdpb.ioNamePtr = (StringPtr)CtoPstr(npath);
if (PBHSetVol(&wdpb, FALSE) != noErr) {
return((int)NULL);
}
#endif
#ifdef TEST
fprintf( stderr, "opendir: %s\n", npath );
#endif
#if DEBUG
printf("wd.ioVRefNum = %x, wd.ioWDDirID = %lx\n", wd.ioVRefNum, wd.ioWDDirID);
#endif
return(noErr);
}
#ifdef TEST
main()
{
char command[100];
gets( command );
fprintf( stderr, "%d\n", chdir( command ));
}
#endif